﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace TrenchcoatRobots.Datatypes.Input {
	enum MouseButton { Left, Middle, Right, Extra1, Extra2 };
	/// <summary>
	/// Mouse input is a class for getting mouse movement.
	/// </summary>
	class MouseInput : GameInput {
		public MouseButton PositiveKey { get; set; }
		public MouseButton NegativeKey { get; set; }
		bool useNegative;

		public override void Update( ref MouseState ms ) {
			base.Value = 0;
			switch ( PositiveKey ) {
				case MouseButton.Left:
					if ( ms.LeftButton == ButtonState.Pressed ) {
						base.Value += 1;
					}
					break;
				case MouseButton.Right:
					if ( ms.RightButton == ButtonState.Pressed ) {
						base.Value += 1;
					}
					break;
				case MouseButton.Middle:
					if ( ms.MiddleButton == ButtonState.Pressed ) {
						base.Value += 1;
					}
					break;
				case MouseButton.Extra1:
					if ( ms.XButton1 == ButtonState.Pressed ) {
						base.Value += 1;
					}
					break;
				case MouseButton.Extra2:
					if ( ms.XButton2 == ButtonState.Pressed ) {
						base.Value += 1;
					}
					break;
			}
			if ( useNegative ) {
				switch ( PositiveKey ) {
					case MouseButton.Left:
						if ( ms.LeftButton == ButtonState.Pressed ) {
							base.Value += -1;
						}
						break;
					case MouseButton.Right:
						if ( ms.RightButton == ButtonState.Pressed ) {
							base.Value += -1;
						}
						break;
					case MouseButton.Middle:
						if ( ms.MiddleButton == ButtonState.Pressed ) {
							base.Value += -1;
						}
						break;
					case MouseButton.Extra1:
						if ( ms.XButton1 == ButtonState.Pressed ) {
							base.Value += -1;
						}
						break;
					case MouseButton.Extra2:
						if ( ms.XButton2 == ButtonState.Pressed ) {
							base.Value += -1;
						}
						break;
				}
			}
		}

		public MouseInput( MouseButton positiveKey, string name )
			: base( name ) {
			PositiveKey = positiveKey;
			useNegative = false;
		}
		public MouseInput( MouseButton positiveKey, MouseButton negativeKey, string name )
			: base( name ) {
			PositiveKey = positiveKey;
			NegativeKey = negativeKey;
			useNegative = true;
		}
	}
}
